<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>xmake</title>
  <link rel="icon" href="/assets/img/favicon.ico">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="description" content="Description">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <link href="/assets/npm/github-markdown/github-markdown.min.css" rel="stylesheet">
  <style>
	.markdown-body {
		box-sizing: border-box;
		min-width: 200px;
		max-width: 980px;
		margin: 0 auto;
		padding: 45px;
	}

	@media (max-width: 767px) {
		.markdown-body {
			padding: 15px;
		}
	}
  </style>
</head>
<body>
<article class="markdown-body">
<h4>This is a mirror page, please see the original page: </h4><a href="https://xmake.io/#/features/trybuild">https://xmake.io/#/features/trybuild</a>
<div id="wwads-panel" class="wwads-cn wwads-vertical wwads-sticky" data-id="239" style="max-width:180px;bottom:20px;right:20px;width:200px;height:260px;background:#fff;position:fixed"></div>
</br>
    <script type="text/javascript" charset="UTF-8" src="https://cdn.wwads.cn/js/makemoney.js" async></script>
<script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CE7I52QU&placement=xmakeio" id="_carbonads_js"></script>
<style>
#carbonads {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
  Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
}

#carbonads {
  display: flex;
  max-width: 330px;
  background-color: hsl(0, 0%, 98%);
  box-shadow: 0 1px 4px 1px hsla(0, 0%, 0%, .1);
}

#carbonads a {
  color: inherit;
  text-decoration: none;
}

#carbonads a:hover {
  color: inherit;
}

#carbonads span {
  position: relative;
  display: block;
  overflow: hidden;
}

#carbonads .carbon-wrap {
  display: flex;
}

.carbon-img {
  display: block;
  margin: 0;
  line-height: 1;
}

.carbon-img img {
  display: block;
}

.carbon-text {
  font-size: 13px;
  padding: 10px;
  line-height: 1.5;
  text-align: left;
}

.carbon-poweredby {
  display: block;
  padding: 8px 10px;
  background: repeating-linear-gradient(-45deg, transparent, transparent 5px, hsla(0, 0%, 0%, .025) 5px, hsla(0, 0%, 0%, .025) 10px) hsla(203, 11%, 95%, .4);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
  font-size: 9px;
  line-height: 1;
}
</style>
    <h1 id="tringtobuildwithotherbuildsystems">Tring to build with other build systems</h1>
<p>Xmake v2.3.1 and above directly interface with other third-party build systems. Even if other projects do not use xmake.lua for maintenance, Xmake can directly call other build tools to complete the compilation. Then the user can directly use a third-party build tool to compile, so why use Xmake to call it? The main benefits are:</p>
<ol>
<li>Completely consistent behavior, simplifying the compilation process. No matter which other build system is used, you only need to execute the Xmake command to compile. Users no longer need to study the different compilation processes of other tools.</li>
<li>Docking the configuration environment of <code>xmake config</code>, reuse the platform detection and SDK environment detection of xmake, simplify the platform configuration.</li>
<li>Docking cross-compilation environment, even for projects maintained with Autotools, you can quickly cross-compile through Xmake.</li>
</ol>
<h2 id="supportedbuildsystems">Supported build systems</h2>
<ul>
<li>Autotools (support for cross-compiling with Xmake)</li>
<li>XCodeBuild</li>
<li>CMake (support for cross-compiling with Xmake)</li>
<li>Make</li>
<li>MSBuild</li>
<li>Scons</li>
<li>Meson</li>
<li>Bazel</li>
<li>NdkBuild</li>
<li>Ninja</li>
</ul>
<h2 id="automaticallydetectbuildsystemandcompile">Automatically detect build system and compile</h2>
<p>For example, for a project maintained using cmake, executing Xmake directly in the project root directory will automatically trigger a detection mechanism, detect CMakeLists.txt, and then prompt the user if cmake is needed to continue compiling.</p>
<pre><code class="lang-bash">$ xmake 
note: CMakeLists.txt found, try building it (pass -y or --confirm=y/n/d to skip confirm)?
please input: y (y/n)
-- Symbol prefix:
-- Configuring done
-- Generating done
-- Build files have been written to:/Users/ruki/Downloads/libpng-1.6.35/build
[  7%] Built target png-fix-itxt
[ 21%] Built target genfiles
[ 81%] Built target png
[ 83%] Built target png_static
...
output to/Users/ruki/Downloads/libpng-1.6.35/build/artifacts
build ok!
</code></pre>
<h2 id="seamlesslyusingthexmakecommand">Seamlessly, using the Xmake command</h2>
<p>Currently supports common commands such as <code>xmake clean</code>,<code>xmake --rebuild</code> and <code>xmake config</code> to seamlessly interface with third-party systems. We can directly clean the compiled output files of the cmake maintenance project</p>
<pre><code class="lang-bash">$ xmake clean
$ xmake clean --all
</code></pre>
<p>If you bring <code>--all</code> to perform the cleanup, all files generated by autotools/cmake will be cleared, not only the object files. The default <code>xmake</code> is docked with incremental build behavior, but we can also force a quick rebuild:</p>
<pre><code class="lang-bash">$ xmake --rebuild
</code></pre>
<h2 id="manuallyswitchthespecifiedbuildsystem">Manually switch the specified build system</h2>
<p>If there are multiple build systems under maintenance in a project, such as the libpng project, which comes with Autotools/CMake/Makefile and other build system maintenance, Xmake defaults to using Autotools by default. If you want to force switch to other build systems, you can execute:</p>
<pre><code class="lang-bash">$ xmake f --trybuild=[autotools|cmake|make|msbuild|..]
$ xmake
</code></pre>
<p>In addition, the <code>--trybuild=</code> parameter is configured to manually specify the default build system, and the subsequent build process will not prompt the user for selection.</p>
<h2 id="crosscompilefast">Cross compile fast!</h2>
<p>As we all know, although many projects maintained by Autotools support cross-compilation, the configuration process of cross-compilation is very complicated. There are still many differences in different toolchain processing methods, and many pits will be stepped in the middle.</p>
<p>Even if you run through a toolchain&#39;s cross-compilation, if you switch to another toolchain environment, it may take a long time, and if you use Xmake, you usually only need two simple commands:</p>
<p>!> At present CMake/Autotools supports cross-compilation of Xmake.</p>
<h3 id="crosscompileandroidplatform">Cross compile android platform</h3>
<pre><code class="lang-bash">$ xmake f -p android --trybuild=autotools [--ndk=xxx]
$ xmake
</code></pre>
<p>!> Among them, the --ndk parameter configuration is optional. If the user sets the ANDROID_NDK_HOME environment variable, or if the ndk is placed in ~/Library/Android/sdk/ndk-bundle, Xmake can automatically detect it.</p>
<p>Is not it simple? If you think this is not much, then you can directly operate <code>./configure</code> to configure cross-compilation. You can see this document for comparison: <a href="https://developer.android.com/ndk/guides/other_build_systems#autoconf">Using NDK with other compilation systems</a>.</p>
<p>To put it bluntly, you probably have to do this, you may not be able to do it once:</p>
<pre><code class="lang-bash">$ export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/$HOST_TAG
$ export AR=$TOOLCHAIN/bin/aarch64-linux-android-ar
$ export AS=$TOOLCHAIN/bin/aarch64-linux-android-as
$ export CC=$TOOLCHAIN/bin/aarch64-linux-android21-clang
$ export CXX=$TOOLCHAIN/bin/aarch64-linux-android21-clang++
$ export LD=$TOOLCHAIN/bin/aarch64-linux-android-ld
$ export RANLIB=$TOOLCHAIN/bin/aarch64-linux-android-ranlib
$ export STRIP=$TOOLCHAIN/bin/aarch64-linux-android-strip
$ ./configure --host aarch64-linux-android
$ make
</code></pre>
<p>If it is CMake, cross-compilation is not an easy task. For the Android platform, this configuration is required.</p>
<pre><code class="lang-bash">$ cmake \
     -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake \
     -DANDROID_ABI=$ABI \
     -DANDROID_NATIVE_API_LEVEL=$MINSDKVERSION \
     $OTHER_ARGS
</code></pre>
<p>For the iOS platform, I did not find a short-answer configuration method, but found a third-party iOS toolchain configuration, which is very complicated: <a href="https://github.com/leetal/ios-cmake/blob/master/ios.toolchain.cmake">https://github.com/leetal/ios-cmake/blob/master/ios.toolchain.cmake</a></p>
<p><!-- What? -->
</p>
<p>For MinGW, it is another way. I have been tossing about the environment for a long time, which is very tossing.</p>
<p>After using XMake, whether it is CMake or Autotools, cross-compilation is very simple, and the configuration method is exactly the same, streamlined and consistent.</p>
<h3 id="crosscompileiphoneosplatform">Cross compile iPhoneOS platform</h3>
<pre><code class="lang-bash">$ xmake f -p iphoneos --trybuild=[cmake|autotools]
$ xmake
</code></pre>
<h3 id="crosscompilemingwplatform">Cross-compile MinGW platform</h3>
<pre><code class="lang-bash">$ xmake f -p mingw --trybuild=[cmake|autotools] [--mingw=xxx]
$ xmake
</code></pre>
<h3 id="usingothercrosscompilationtoolchains">Using other cross-compilation toolchains</h3>
<pre><code class="lang-bash">$ xmake f -p cross --trybuild=[cmake|autotools] --sdk=/xxxx
$ xmake
</code></pre>
<p>For more cross compilation configuration details, please refer to the document: <a href="https://xmake.io/#/guide/configuration?id=cross-compilation">Cross Compilation</a>, except for an additional <code>--trybuild=</code> parameter, all other cross-compilation configuration parameters are completely universal.</p>
<h2 id="passinguserconfigurationparameters">Passing user configuration parameters</h2>
<p>We can use <code>--tryconfigs=</code> to pass additional configuration parameters of the user to the corresponding third-party build system. For example: autotools will be passed to <code>. / Configure</code>, cmake will be passed to the<code>cmake</code> command.</p>
<pre><code class="lang-bash">$ xmake f --trybuild=autotools --tryconfigs="-enable-shared=no"
$ xmake
</code></pre>
<p>For example, the above command, pass <code>--enable-shared=no</code> to<code>./configure</code> to disable dynamic library compilation. In addition, for <code>--cflags</code>,<code>--includedirs</code> and <code>--ldflags</code>, you don&#39;t need to pass<code>--tryconfigs</code>, you can pass the built-in parameters like <code>xmake config --cflags=</code> to pass through.</p>
<h2 id="examplesofcompilingotherbuildsystem">Examples of compiling other build system</h2>
<h3 id="generalcompilation">General Compilation</h3>
<p>In most cases, the compilation method after each docking system is consistent, except for the <code>--trybuild=</code> configuration parameter.</p>
<pre><code class="lang-bash">$ xmake f --trybuild=[autotools|cmake|meson|ninja|bazel|make|msbuild|xcodebuild]
$ xmake
</code></pre>
<p>!> We also need to make sure that the build tool specified by --trybuild is installed and working properly.</p>
<h3 id="buildingandroidjniprograms">Building Android JNI programs</h3>
<p>If <code>jni/Android.mk</code> exists in the current project, then Xmake can directly call NdkBuild to build the jni library.</p>
<pre><code class="lang-bash">$ xmake f -p android --trybuild=ndkbuild [--ndk =]
$ xmake
</code></pre>
<p>We also provided <a href="https://github.com/xmake-io/xmake-gradle">xmake-gradle</a> to build jni library in gradle, you can see <a href="https://xmake.io/#/plugin/more_plugins?id=gradle-plugin-jni">Uses xmake to build JNI in Gradle</a></p>
</article>
</body>
</html>